package com.ruoyi.system.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.ShopFeeVo;
import com.ruoyi.system.service.SummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;
import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * @program: zhihiwuye
 * @author: fcs
 * @data: 2024-03-08 14:22
 * @description: TODO
 */
@RestController
@RequestMapping("/system/summary")
public class SummaryController {
    @Autowired
    private SummaryService summaryService;

    @PreAuthorize("@ss.hasPermi('system:summary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getShopInfo(@PathVariable("id") Long id)
    {
        if (summaryService.selectShopInfoById(id) == null){
            return error("未找到该店铺！");
        }
        else {
            return success(summaryService.selectShopInfoById(id));
        }
    }

    @PreAuthorize("@ss.hasPermi('system:summary:query')")
    @GetMapping(value = "/house/{id}")
    public TableDataInfo getHouseFee(@PathVariable("id") Long id)
    {
        startPage();
        List<ShopFeeVo> list = summaryService.selectHouseFee(id);
        return getDataTable(list);
    }

    /**
     * 响应请求分页数据
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected TableDataInfo getDataTable(List<?> list)
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }


}
